package ui;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import node.Node;

public class ControllerStartNode implements ActionListener {
	
	private StartNode window = null;
	
	public void start(){
		final ControllerStartNode controller = this;
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					window = new StartNode();
					window.getStartNodeButton().addActionListener(controller);
					window.getFrame().setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public static void main(String[] args) {
		ControllerStartNode controller = new ControllerStartNode();
		controller.start();	
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {	
		if(!(window.getFileField().getText().isEmpty()) && (window.getCheckDiscovery().isSelected())){
			Node node = new Node(window.getFileField().getText(),true);
			ControllerDiscoveryUi controller = new ControllerDiscoveryUi();
			controller.start();
			ControllerMainWindow main_controller = new ControllerMainWindow();
			main_controller.start();
			this.window.getFrame().setVisible(false);	
		}
		else if(!(window.getFileField().getText().isEmpty()) && (window.getCheckStartNode().isSelected()))
		{	
			Node node =new Node(window.getFileField().getText(),false);
			ControllerMainWindow main_controller = new ControllerMainWindow();
			main_controller.start();
			this.window.getFrame().setVisible(false);
		}
	}
}
